<?php namespace Home\Controller;

use Hdphp\Controller\Controller;

//注册登录控制器
class EnterController extends Controller{
	private $model;//存放模型对象
	public function __init(){
		$this->model=new \Common\Model\User;
	}

	//注册
	public function register(){
		if (IS_POST) {
			//注册用户
			if (!$this->model->store()) {
				$this->ajax(['status'=>false,'message'=>$this->model->getError()]);
			}else{
				//注册成功
				$this->ajax(['status'=>true,'message'=>'注册成功']);
			}
		}
		View::make();
	}


	//登录
	public function login(){
		if (IS_POST) {
			//登录验证
			if(!$this->model->checklogin()) {
				$this->ajax(['status'=>false,'message'=>$this->model->getError()]);
			}else{
				//登录成功
				$this->ajax(['status'=>true,'message'=>'登录成功']);
			}
		}
		View::make();
	}

	//验证码
	public function code(){
		Code::num(C('webset.CODE_LEN'))->fontcolor(C('webset.CODE_COLOR'))->height(46)->width(100)->make();
	}

	//退出登录
	public function quit(){
		session_unset($_SESSION['homeInfo']);
		session_destroy();
		go(__ROOT__.'/index.html');
	}

	//验证账号是否已注册
	public function checkAccount(){
		$account=Q('post.a','','strtolower');
		if (!$this->model->registered($account)) {
			echo 0;
		}else{
			echo 1;
		}
	}

	//用户协议页
	public function privacy(){
		View::make();
	}



}